import axios from "axios";
import Vue from 'vue';


let baseUrl = process.env.API_ROOT + '/api/webchart/';

const ajaxMethod = {
  ajax: function(type, method, param) {
    return axios({
      method: "get",
      url: baseUrl + method,
      params: param
    })
    .then(response => {
      return response.data;
    })
    .catch(error => {
      console.log("get请求失败:", error);
    });
  },

  ajaxPost: function(type, method, param) {
    Vue.$vux.loading.show({
      text: '加载中'
    });
    return axios({
      method: "post",
      url: baseUrl + method,
      data: param
    })
    .then(response => {
      Vue.$vux.loading.hide();
      return response.data;
    })
    .catch(error => {
      Vue.$vux.loading.hide();
      console.log("post请求失败:", error);
    });
  }
};
//输出接口请求方法
export default {
  get: function(method, param) {
    return ajaxMethod.ajax("get", method, param);
  },
  post: function(method, param) {
    return ajaxMethod.ajaxPost("post", method, param);
  }
};
